package com.hongkzh.www.adv.service;

import com.google.common.collect.Lists;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

/**
 * @author martins
 */
public class CarouselService extends BaseService{

    public List<Record> getCarouselList(){
        SqlPara sqlPara = Db.getSqlPara("carousel.getCarouselList");
        List<Record> records=Db.find(sqlPara);
        if(records==null){
            records= Lists.newArrayList();
        }
        for (Record r:records) {
            doFilePath(r);
            //r.set("imgSrc", PropKit.get("fileServer")+ r.get("imgSrc"));
        }
        return records;

    }
    public List<Record> getCategoryList(){
        SqlPara sqlPara = Db.getSqlPara("carousel.getCategoryList");
        List<Record> records=Db.find(sqlPara);
        if(records==null){
            records=Lists.newArrayList();
        }
        List<Record> rs= Lists.newArrayList();
        for (Record r:records) {
            Record d=new Record();
            doFilePath(r);
            d.set("imgSrc",  r.getStr("imgSrc"));
            d.set("imgRank",   r.getStr("imgRank"));
            if(StrKit.notBlank(r.getStr("imgLinks"))){
                d.set("type",10);
                d.set("imgLinks", r.getStr("imgLinks"));
                d.set("id","");
                d.set("category",r.getStr("imgNote"));
            }
            if(StrKit.notBlank(r.getStr("mediaCategory"))){
                d.set("type",1);
                d.set("id",r.getStr("mediaCategoryId"));
                d.set("category",r.getStr("mediaCategory"));
            }
            if(StrKit.notBlank(r.getStr("enterpriseCategory"))){
                d.set("type",2);
                d.set("id",r.getStr("enterpriseCategoryId"));
                d.set("category",r.getStr("enterpriseCategory"));
            }
            if(StrKit.notBlank(r.getStr("cityCategory"))){
                d.set("type",3);
                d.set("id",r.getStr("cityCategoryId"));
                d.set("category",r.getStr("cityCategory"));
            }
            if(StrKit.notBlank(r.getStr("traditionCategory"))){
                d.set("type",4);
                d.set("id",r.getStr("traditionCategoryId"));
                d.set("category",r.getStr("traditionCategory"));
            }
            rs.add(d);
        }
        return rs;

    }

    public List<Record> getEnterpriseCarouselList() {
        SqlPara sqlPara = Db.getSqlPara("carousel.getEnterpriseCarouselList");
        List<Record> records=Db.find(sqlPara);
        if(records==null){
            records=Lists.newArrayList();
        }
        for (Record r:records) {
            doFilePath(r);
        }
        return records;
    }
}
